"""Vice functional doctests.  This module collects all *.txt
files in the tests directory and runs them. (stolen from Plone via PloneBoard)
"""

import os, sys

import glob
import doctest
import unittest
from Globals import package_home
from Products.PloneTestCase import PloneTestCase
from Products.PloneTestCase.layer import onsetup
from Testing.ZopeTestCase import FunctionalDocFileSuite as Suite, FunctionalTestCase

from plone.syndication.outbound.config import GLOBALS

from plone.syndication.outbound.tests.vicetestcase \
    import ViceFunctionalTestCase

OPTIONFLAGS = (doctest.REPORT_ONLY_FIRST_FAILURE |
               doctest.ELLIPSIS |
               doctest.NORMALIZE_WHITESPACE)

def list_doctests(prefix=''):
    home = package_home(GLOBALS)
    doctests = [os.path.sep.join(['tests',os.path.basename(filename)]) 
                for filename in 
                glob.glob(os.path.sep.join([home, 'tests', prefix + '*.txt']))]
    doctests.extend([os.path.basename(filename) for filename in
                     glob.glob(os.path.sep.join([home, prefix + '*.py']))])
    return doctests


def test_suite():
    return unittest.TestSuite(
        [Suite(filename,
               optionflags=OPTIONFLAGS,
               package='plone.syndication.outbound',
               test_class=FunctionalTestCase)
         for filename in list_doctests()]
        )
